package com.realbrand.net.realbrandpay.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.base.BaseActivity;
import com.realbrand.net.realbrandpay.test.TestActivity;
import com.realbrand.net.realbrandpay.ui.activity.ADSActivity;
import com.realbrand.net.realbrandpay.ui.activity.shopcar.ShopCarActivity;
import com.realbrand.net.realbrandpay.untils.Static;
import com.realbrand.net.realbrandpay.zxing.app.CaptureActivity;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/6/13.
 */

public class WebAdsActivity extends BaseActivity {
    @BindView(R.id.test_toolbar)
    Toolbar testToolbar;
    @BindView(R.id.test_webView)
    WebView testWebView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        testToolbar.setTitle("");
        testToolbar.setNavigationIcon(R.mipmap.ic_back);
        setSupportActionBar(testToolbar);
        testToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShopCarActivity.mBoolean = true;
                Intent intent = new Intent(WebAdsActivity.this, CaptureActivity.class);
                Bundle bundle_scan = new Bundle();
                bundle_scan.putString(Static.BundleKey, ADSActivity.VALUE_ADS);
                intent.putExtras(bundle_scan);
                startActivity(intent);
                finish();
            }
        });
        String stringExtra = getIntent().getStringExtra("ad");
        testWebView.loadUrl(stringExtra);
        WebSettings webSettings = testWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);//允许使用js
        testWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        testWebView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && testWebView.canGoBack()) {  //表示按返回键
                        testWebView.goBack();   //后退
                        //webview.goForward();//前进
                        return true;    //已处理
                    }
                }
                return false;
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.test_act_layout;
    }

    @Override
    protected void setOnClick() {

    }

    @Override
    public void onClick(View v) {

    }
}
